package service.impl;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import entity.User;
import service.CartService;
import util.Constant;
import util.CookieUtil;
import util.ObjectFactory;

public class CartFactory {
	public static CartService getInstance(Map<String, Object> session,HttpServletRequest httpReq) throws Exception{
		CartService cart = (CartService) session.get(Constant.CART);
		if (cart==null) {
			cart=ObjectFactory.getInstance(CartService.class);
			User user = (User)session.get("user");
			String uid = user.getId()+"";
			String value = CookieUtil.findCookie(uid, httpReq);
			if (value!=null) {
				cart.load(value);
			}
			session.put(Constant.CART, cart);
		}
		return cart;
	}
}
